<?php
    date_default_timezone_set('Asia/Bangkok');
    error_reporting(E_ALL & ~E_NOTICE);    
    
    function connect(){  //Connect to Database
        global $hostname;
        global $user;
        global $password;
        global $dbname;
        global $mysqli;

        $hostname="localhost";
        $user="bp_rwcp";
        $password="1885Njxa";
        $dbname="bp_rwcp";

        $mysqli=new mysqli($hostname,$user,$password,$dbname);

        $mysqli->query("SET NAMES UTF8");

        return $mysqli;
    }
    
    function ofAuthenticated(){
        $mysqli=  connect();
        $query="
            select  *
            from    officer
            where   user='".$_SESSION["ofAuthen"]["user"]."' and
                    pass='".$_SESSION["ofAuthen"]["pass"]."'
            ";
        $result=$mysqli->query($query);
        if($result->num_rows>0){
            return TRUE;
        }else{
            return FALSE;
        }
    }
    
    function memAuthenticated(){
        $mysqli=  connect();
        if($_SESSION["memAuthen"]["user"]=="" or $_SESSION["memAuthen"]["user"]==""){
            return FALSE;
        }else{
            $query="
                select  *
                from    member
                where   user='".$_SESSION["memAuthen"]["user"]."' and
                        pass='".$_SESSION["memAuthen"]["pass"]."'
                ";
            $result=$mysqli->query($query);
            if($result->num_rows>0){
                return TRUE;
            }else{
                return FALSE;
            }
        }
    }
    
    function noCache(){
        header("Cache-Control: no-cache, must-revalidate");
    }

    function headerEncode(){
        header('Content-Type: text/html; charset=utf-8');
    }
    
    function arraySort($array,$sortCol,$ascDesc){
        if(is_array($array)){
            $sortArray = array(); 

            foreach($array as $arrayTemp){ 
                foreach($arrayTemp as $key=>$value){ 
                    if(!isset($sortArray[$key])){ 
                        $sortArray[$key] = array(); 
                    }
                    $sortArray[$key][] = $value; 
                } 
            } 

            $orderby = $sortCol; //change this to whatever key you want from the array 

            array_multisort($sortArray[$orderby],$ascDesc,$array);
            return $array;
        }else{
            return FALSE;
        }
    }